

//页面左右划动
function HomeScroll(a, b) {
    function g() {
        var g = $(window).scrollLeft()
            , h = $(window).scrollTop()
            , i = $(document).height()
            , j = $(window).height()
            , k = c.height()
            , l = d.height()
            , m = k > l ? f : e
            , n = k > l ? d : c
            , o = k > l ? c.offset().left + c.outerWidth(!0) - g : d.offset().left - c.outerWidth(!0) - g
            , p = k > l ? l : k
            , q = k > l ? k : l
            , r = parseInt(q - j) - parseInt(p - j);
        $(a + "," + b).removeAttr("style"),
            j > i || p > q || m > h || p - j + m >= h ? n.removeAttr("style") : j > p && h - m >= r || p > j && h - m >= q - j ? n.attr("style", "margin-top:" + r + "px;") : n.attr("style", "_margin-top:" + (h - m) + "px;position:fixed;left:" + o + "px;" + (j > p ? "top" : "bottom") + ":0;")
    }
    if ($(a).length > 0 && $(b).length > 0) {
        var c = $(a)
            , d = $(b)
            , e = c.offset().top
            , f = d.offset().top;
        $(window).resize(g).scroll(g).trigger("resize")
    }
}
HomeScroll(".ContL",".ContR");
HomeScroll(".ContL-mall",".ContR-mall");

// 切换hover
$(".switch_hover .switchlabe .tab").mouseenter(function () {
    var i = $(this).index();
    $(this).addClass('on').siblings().removeClass('on');
    $(this).parents(".switch_hover").find(".switchbox .switchitem ").eq(i).show().siblings().hide();
    $(this).parents(".sswitch_hover").find(".switchmore a").eq(i).show().siblings().hide();
    $(window).trigger('scroll');
})

$(".switch_ck .switchlabe .tab").click(function () {
    var i = $(this).index();
    $(this).addClass('on').siblings().removeClass('on');
    $(this).parents(".switch_ck").find(".switchbox .switchitem ").eq(i).show().siblings().hide();
    $(this).parents(".switch_ck").find(".switchmore a").eq(i).show().siblings().hide();
    $(window).trigger('scroll');
})

// 换一换
var Changeit_i = 0;
$(".Changeit .hyh").click(function () {
    var i = $(this).parents(".Changeit").find(".itemhyh").size();
    var index = $(this).parents(".Changeit").find(".itemhyh:visible").index();
    index++;
    if (index >= i) {
        index = 0;
    }
    $(this).parents(".Changeit").find(".itemhyh").eq(index).show().siblings().hide();
})

// 首页自动切换
if($(".swiperlunbox .swiper-slide").size()>=1){
    $(".swiperlunbox").each(function(index){
        var swiperlunbox='swiperlunbox'+index;
        $(this).addClass(swiperlunbox)
        var delay=5000;
        if($(this).attr("data-time")){
            delay=$(this).attr("data-time");
        }
        swiperlunbox = new Swiper('.'+swiperlunbox, {
            speed: 400,
            lazy: {
                loadPrevNext: true,
              },
            observer:true,
	       observeParents:true,
            autoplay: {
                delay: delay,
                disableOnInteraction: false,
            },
            navigation: {
                nextEl: '.'+swiperlunbox+' .swiper-next',
                prevEl: '.'+swiperlunbox+' .swiper-prev',
            },
        });
    })
}

// 频道列表页面的轮播
if($(".swiperlist .swiper-slide").size()>=1){
    $(".swiperlist").each(function(index){
        var swiperlist='swiperlist'+index;
        $(this).addClass(swiperlist)
        swiperlist = new Swiper('.'+swiperlist+' .swiper' , {
            speed: 400,
            spaceBetween: 16,
            slidesPerView: 2,
            lazy: {
                loadPrevNext: true,
                loadPrevNextAmount: 2,
              },
            observer:true,
	       observeParents:true,
            navigation: {
                nextEl: '.'+swiperlist+' .swipernext',
                prevEl: '.'+swiperlist+' .swiperprev',
            },
        });
    })
}
// 列表页面的精品
if($(".swiperimgslide .swiper-slide").size()>=1){
    $(".swiperimgslide").each(function(index){
        var swiperimgslide='swiperimgslide'+index;
        $(this).addClass(swiperimgslide)
        var Group=1;
        if($(this).attr("data-Group")){
            Group=Number($(this).attr("data-Group"));
        }
        swiperimgslide = new Swiper('.'+swiperimgslide, {
            slidesPerView: 4,
            slidesPerGroup:Group,
            spaceBetween: 16,
            lazy: {
                loadPrevNext: true,
                loadPrevNextAmount: 4,
              },
            observer:true,
            observeParents:true,
            navigation: {
                nextEl: '.'+swiperimgslide+' .swipernext',
                prevEl: '.'+swiperimgslide+' .swiperprev',
            },
            pagination: {
                el: "."+swiperimgslide+" .swiper-pagination",
                clickable :true,
              },
        });
    })
  
}
// 列表页面时间的筛选
function timescreen(){
    //执行一个laydate实例
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    month = (month > 9) ? month : ("0" + month);
    day = (day < 10) ? ("0" + day) : day;
    var today = year + "-" + month + "-" + day;
//    $(".Leftnav .lis .calendar .input").val(today);
    var resoid = $("#resoid").val();
    var resotime = $('#resotime').val();
    laydate.render({
      elem: '#calendar', //指定元素,
      value: resotime,
      done:function(value, date, endDate){
        $(".Leftnav .lis .calendar .input").val(value);
        var url = $('#resourl').val();
        window.location.href = url + resoid + '-' + value + '/';
      }
    });
 }
 if($(".calendar").size()>=1){
    timescreen()
 }
 // 分享
$(".sharebox .hovershare").hover(function(){
        $(".share").fadeIn();
        if( $(".social-share .icon-link").size()<1){
           $(".social-share").prepend('<a   class="icon-link copy"><u ></u><span>复制链接</span></a>')
           $(".social-share .icon-wechat").append('<u></u><span>微信</span>')
           $(".social-share .icon-weibo").append('<u></u><span>新浪微博</span>')
           $(".social-share .icon-qzone").append('<u></u><span>QQ空间</span>')
           var copyText =window.location.href;//获取对象
           var clipboard = new Clipboard('.copy', {
               text: function () {
                 return copyText;
               }
             });
             clipboard.on('success', function (e) {
               alert('链接复制成功')
             });
             clipboard.on('error', function (e) {
               console.log('链接复制失败');
             });
        }
 },function(){
   $(".share").fadeOut();
});
//影视详情导航栏
if ($(".switchnav .swiper .swiper-slide").size() >= 1) {
    var side = 'auto';
    var switchnav = new Swiper('.switchnav .swiper', {
        slidesPerView: side,
    });
    $(".switchnav .swiper .swiper-slide").each(function (index) {
        if ($(this).hasClass("on") && index > 4) {
            var index_ = $(this).index();
            switchnav.slideTo(index_, false);//切换到第一个slide，速度为1秒;
        }
    })
}
// 轮播下
if($(".swiperjietu .swiper-slide").size()>=1){
    $(".swiperjietu").each(function(index){
        var box=$(this).find(".swiper .swiper-slide").eq(0).find("img");
        var swiperjietu='swiperjietu'+index;
        $(this).addClass(swiperjietu)
        var View=2;
        var imgo = new Image();
            imgo.src = box.attr('src');
            imgo.onload=function(){
                var img_h=imgo.height;
                var img_w=imgo.width;
                if (img_h>img_w){
                    box.parents(".swiperjietu").find(".swiper_wrap").addClass('swiper-h');
                    View=3;
                }
                swiper_();
            }
            function swiper_(){
                swiperjietu = new Swiper('.'+swiperjietu+' .swiper', {
                    speed: 400,
                    slidesPerView:View,
                    spaceBetween: 16,
                    lazy: {
                        loadPrevNext: true,
                      },
                    observer:true,
                   observeParents:true,
                    navigation: {
                        nextEl: '.'+swiperjietu+' .swiper-button-next',
                        prevEl: '.'+swiperjietu+' .swiper-button-prev',
                    },
                });
            }
    })
}
// 资源详情点击下载
$(".ziyuandown .down .btn.on").click(function(){
    $(this).parents(".down").find(".lisbox").slideToggle()
})
$(".ziyuandown .down .lisbox .close").click(function(){
    $(this).parents(".down").find(".lisbox").slideToggle()
})

// UP回到顶部
$("body").append("<div class='QZ-up icon'></div>")
$(window).scroll(function () {
    var scroll_len = $(window).scrollTop();
    if (scroll_len > 120) {
        $('.QZ-up').fadeIn();
    } else {
        $('.QZ-up').fadeOut();
    }
});
$('.QZ-up').click(function () {
    $("body,html").animate({ scrollTop: 0 }, 300);
});

  //详情页面左右切换;
  (function () {
	if($(".pages  .tips").size()>=1){
		'use strict';
		if(typeof(Cdetail_total) == "undefined"){
			Cdetail_total = $(".pagewrap .pagination .next").prev().text();
		}
		var gkeyup_k = 0;
		var gkeyup_n = 0;
		var gkeyup_U1 = BeginUrl(location.href);
		$(document).keyup(function(event){
			var isFocus= $("input , textarea").is(":focus"); 
			var e = event || window.event;
			gkeyup_k = e.keycode || e.which;
			if (gkeyup_k == 37 && isFocus==false) {
				//left
				PlusUrl('-');
   			}else if (gkeyup_k == 39 && isFocus==false) {
				//right
				PlusUrl('+');
   			}
    		return;
		}); 
		function BeginUrl(u) {
			var uTmp = '';
			if (u.indexOf('_') > 0) {
				uTmp = u.substring(0,u.indexOf('_'));
				gkeyup_n = u.substring(u.indexOf('_') + 1,u.indexOf('.html'));
    		}
    		else {
    			uTmp = u.substring(0,u.indexOf('.html'));
    			gkeyup_n = 1;
    		}
    		return uTmp;
  		}
  		function PlusUrl(n1) {
  			var nTmp = gkeyup_n;
  			if (n1 == '-') {
  				nTmp--;
  			}else if (n1 == '+') {
  				nTmp++;
    		}
    		if (nTmp <=0) {
    			gkeyup_n=1;
    			return;
    		}else if(nTmp > Cdetail_total){
    			gkeyup_n=Cdetail_total;
    			return;
    		}
    		AddUrl(nTmp);
		}
  		function AddUrl(u) {
    		//跳转...
    		if (u === null) {
      			return;
    		}
   			if (u%1 === 0 && u <= Cdetail_total) {
	      		if (u <= 1) {
	        		window.location.assign(gkeyup_U1 + '.html');
	      		}else {
	        		window.location.assign(gkeyup_U1 + '_' + u + '.html');
	      		}
   			}else {
      			return;
    		}
  		}
 	}				
})();


